package ioperation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:张熳
 * Date:2025-09-05
 * Time:15:50
 */

//写出你要借阅的图书书名，遍历数组，如果这本书的isborrowed是true，即已经被借阅，则无法再借阅，反之，如果成功借出，则 说明原先是false，此时
//要将其改为true，表示借出，最后记得都要return

public class BorrowOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("借阅图书📖");
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入你要借阅的图书书名📕：");
        String name = scanner.nextLine();

        int currentSize = bookList.getUsedSize();
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            if (book.isIsborrowed()) {
                System.out.println("这本书已经被借阅📂！");
                return;
            }
            if (book.getName().equals(name)) {
                System.out.println("借阅成功✨！");
                book.setIsborrowed(true);
                return;
            }
        }
        System.out.println("没有你要借阅的图书📕！");
    }
}
